use rand::prelude::*;
// use zxcvbn::zxcvbn;

const UPPER: &[u8] = b"ABCDEFGHJKLMNPQRSTUVWXYZ";
const LOWER: &[u8] = b"abcdefghijkmnopqrstuvwxyz";
const NUMBER: &[u8] = b"123456789";
const SYMBOL: &[u8] = b"!@$%^&*_";

pub fn process_genpass(
    len: u8,
    upper: bool,
    lower: bool,
    number: bool,
    symbol: bool,
) -> anyhow::Result<String> {
    let mut rng = rand::thread_rng();
    let mut chars = Vec::new();
    let mut password = String::new();

    if upper {
        chars.extend_from_slice(UPPER);
    }

    if lower {
        chars.extend_from_slice(LOWER);
    }

    if number {
        chars.extend_from_slice(NUMBER);
    }

    if symbol {
        chars.extend_from_slice(SYMBOL);
    }

    chars.shuffle(&mut rng);

    for _ in 0..len {
        if let Some(&code) = chars.choose(&mut rng) {
            password.push(code as char);
        }
    }

    // println!(
    //     "password: {}, strength: {}",
    //     password,
    //     zxcvbn(&password, &[]).score()
    // );

    Ok(password)
}
